feat(BA-5797): add effective permissions resolver for entities#11236
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new full-stack API to resolve a user’s effective RBAC operations per target entity by traversing the scope-chain and self-scope permissions.
Changes:
- Introduces
ResolveEffectivePermissionsAction/ result and wires it into the service layer. - Adds repository + DB source support to compute effective permissions using scope-chain CTE + self-scope union.
- Adds new data types (
EffectivePermissionsInput/Result) and a changelog entry.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ai/backend/manager/services/permission_contoller/service.py | Adds service entrypoint that calls repository resolver and returns action result. |
| src/ai/backend/manager/services/permission_contoller/actions/resolve_effective_permissions.py | Defines action + result DTOs for effective permission resolution. |
| src/ai/backend/manager/services/permission_contoller/actions/init.py | Exposes the new action/result via package exports. |
| src/ai/backend/manager/repositories/permission_controller/repository.py | Adds repository method with resilience policy to call DB source resolver. |
| src/ai/backend/manager/repositories/permission_controller/db_source/db_source.py | Implements resolver by unioning scope-chain and self-scope queries. |
| src/ai/backend/manager/data/permission/role.py | Adds input/output dataclasses for the new resolver. |
| changes/11236.feature.md | Documents the new feature in the changelog. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a34eac6 to
291c723
Compare
bd48aef to
8f1b576
Compare
8f1b576 to
fb2b637
Compare
|
|
||
| @override | ||
| @classmethod | ||
| def entity_type(cls) -> EntityType: |
There was a problem hiding this comment.
Is it intentional that entity_id is a user_id even though entity_type is not USER?
There was a problem hiding this comment.
We decided to not expand/use entity type enum anymore and this abstract method is also deprecated. it is implemented to avoid type check for now
Add resolve_effective_permissions across the full stack (data types → DB source → repository → service/action) to answer "what operations can user X perform on entities [A, B, C]?" Uses a single batched query with the existing scope chain CTE, eliminating N+1 by processing all entity IDs in one DB roundtrip. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…sions Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Clarify that this branch only ships the permission controller service and repository implementations, without the API surface. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
fb2b637 to
3510a48
Compare
|
|
||
| combined_query = sa.union_all(scope_chain_query, self_scope_query) | ||
|
|
||
| permissions: defaultdict[str, set[OperationType]] = defaultdict(set) |
There was a problem hiding this comment.
How about init result dict keys with requested entity ids first? Since the current query does not return information for entity IDs that do not match, it seems better to ensure that it returns an empty set for entity IDs that do not match at all.
| permissions: defaultdict[str, set[OperationType]] = defaultdict(set) | |
| permissions: dict[str, set[OperationType]] = { | |
| entity_id: set() for entity_id in data.target_entity_ids | |
| } |
| def _make_input( | ||
| self, | ||
| fixture: EffectiveFixture, | ||
| entity_type: EntityType = EntityType.VFOLDER, |
There was a problem hiding this comment.
Nit: entity_type seems useless
Summary
resolve_effective_permissionsacross the full stack (data types → DB source → repository → service/action) to answer "what operations can user X perform on entities [A, B, C]?"dict[str, set[OperationType]]mapping entity ID → permitted operationsTest plan
Resolves BA-5797